﻿#include "group_view.h"
#include "ui_group_view.h"
#include"qpainter.h"
#include "DataPro/datapro.h"
#include "QtCharts/QAreaSeries"
#include "QJsonArray"
#include "dialog/myhelper.h"
#include "constant.h"
#include "qtabbar.h"
Group_view::Group_view(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Group_view)
{
    ui->setupUi(this);
    initialVariable();

    ui->tabWidget->tabBar()->close();
    initServer();
    initialWaveChart();
    initialSlots();
    if(Constant::ShowFullScreen)
        this->showFullScreen();


}

Group_view::~Group_view()
{
    delete hr_Chart;
    delete ox_Chart;
    delete mp_Chart;
    delete mp_PieChart;
    delete hrvHist_BarChart;
    delete hrvScatterChart;
    delete hrvARAreaChart;
    delete hrvBallanceChart;
    delete a_hr_Chart;
    delete a_ox_Chart;
    delete a_mp_Chart;
    delete a_fatigure_Chart;
    delete a_depress_Chart;
    delete a_ansiety_Chart;
    delete a_ballance_Chart;
    delete a_activity_Chart;
    delete timer_UpdataChart;
    delete ui;
}
void Group_view::initialVariable()
{
    ui->pushButton_end->setVisible(false);
    hash_data_info.clear();
    btn_num=1;
    ui->tabWidget->setCurrentIndex(0);
}
void Group_view::initialSlots()
{
    connect(ui->mybtn1,SIGNAL(Clicked()),this,SLOT(MyButtionClickeListener1()));
    connect(ui->mybtn2,SIGNAL(Clicked()),this,SLOT(MyButtionClickeListener2()));
    connect(ui->mybtn3,SIGNAL(Clicked()),this,SLOT(MyButtionClickeListener3()));
    connect(ui->mybtn4,SIGNAL(Clicked()),this,SLOT(MyButtionClickeListener4()));
    connect(ui->mybtn5,SIGNAL(Clicked()),this,SLOT(MyButtionClickeListener5()));
    connect(ui->mybtn6,SIGNAL(Clicked()),this,SLOT(MyButtionClickeListener6()));
    connect(ui->mybtn7,SIGNAL(Clicked()),this,SLOT(MyButtionClickeListener7()));
    connect(ui->mybtn8,SIGNAL(Clicked()),this,SLOT(MyButtionClickeListener8()));
    connect(ui->mybtn9,SIGNAL(Clicked()),this,SLOT(MyButtionClickeListener9()));
    connect(ui->mybtn10,SIGNAL(Clicked()),this,SLOT(MyButtionClickeListener10()));
    connect(ui->mybtn11,SIGNAL(Clicked()),this,SLOT(MyButtionClickeListener11()));
    connect(ui->mybtn12,SIGNAL(Clicked()),this,SLOT(MyButtionClickeListener12()));
    connect(ui->mybtn13,SIGNAL(Clicked()),this,SLOT(MyButtionClickeListener13()));
    connect(ui->mybtn14,SIGNAL(Clicked()),this,SLOT(MyButtionClickeListener14()));
    connect(ui->mybtn15,SIGNAL(Clicked()),this,SLOT(MyButtionClickeListener15()));
    connect(ui->mybtn16,SIGNAL(Clicked()),this,SLOT(MyButtionClickeListener16()));
    connect(ui->mybtn17,SIGNAL(Clicked()),this,SLOT(MyButtionClickeListener17()));
    connect(ui->mybtn18,SIGNAL(Clicked()),this,SLOT(MyButtionClickeListener18()));
    connect(ui->mybtn19,SIGNAL(Clicked()),this,SLOT(MyButtionClickeListener19()));
    connect(ui->mybtn20,SIGNAL(Clicked()),this,SLOT(MyButtionClickeListener20()));

    timer_UpdataChart=new QTimer(this);
    timer_UpdataChart->start(3000);
    connect(timer_UpdataChart, SIGNAL(timeout()), this, SLOT(update_a_Data()));
}
void Group_view::update_a_Data()
{
    QDateTime endTime=  QDateTime::currentDateTime();
    qint64 intervalTime = startTime.secsTo(endTime);
    int progress=intervalTime*100.0/NeedTime;
    if(progress>100)
        progress=100;
    ui->label->setText("进度："+QString::number(progress)+"%");
    if(intervalTime>=NeedTime)
    {
        ui->pushButton_end->setVisible(true);
    }
    QHashDataInfoIterator i = hash_data_info.begin();
    QList<double>hr_list;
    QList<double>ox_list;
    QList<double>mp_list;
    QList<double>fatigure_list;
    QList<double>depress_list;
    QList<double>ansiety_list;
    QList<double>ballance_list;
    QList<double>activity_list;
    QList<double>antiPressure_list;
    QList<double>sdp_list;
    QList<double>PhysicalMentalHealth_list;

    for(; i != hash_data_info.end(); ++i)
    {
        DATA_INFO data = i.value();
        if(data.HR>0)
            hr_list.append(data.HR);
        if(data.Ox>0)
            ox_list.append(data.Ox);
        if(data.Spress_List.size()>0)
            mp_list.append(data.Spress_List.last());
        if(data.Fatigure>0)
            fatigure_list.append(data.Fatigure);
        if(data.Depress>0)
            depress_list.append(data.Depress);
        if(data.Ansiety>0)
            ansiety_list.append(data.Ansiety);
        if(data.Ballance>0)
            ballance_list.append(data.Ballance);
        if(data.Activity>0)
            activity_list.append(data.Activity);
        if(data.AntiPress>0)
            antiPressure_list.append(data.AntiPress);
        if(data.SDP>0)
            sdp_list.append(data.SDP);
        if(data.PhysicalMentalHealth>0)
            PhysicalMentalHealth_list.append(data.PhysicalMentalHealth);
    }

    double pmh_a=mean_List(PhysicalMentalHealth_list);

    if(pmh_a>0)
        PhysicalMentalHealth_list_A.append(pmh_a);

    cc.update_A_PieData(0,Tongji(0,hr_list));
    cc.update_A_PieData(1,Tongji(1,ox_list));
    cc.update_A_PieData(2,Tongji(2,mp_list));
    cc.update_A_PieData(3,Tongji(3,fatigure_list));
    cc.update_A_PieData(4,Tongji(4,depress_list));
    cc.update_A_PieData(5,Tongji(5,ansiety_list));
    cc.update_A_PieData(6,Tongji(6,ballance_list));
    cc.update_A_PieData(7,Tongji(7,activity_list));

}
double Group_view::mean_List(QList<double>l)
{
    int len=l.size();
    if(len>0){
        double sum=0;
        for(int i=0;i<len;i++)
        {
            sum+=l.at(i);
        }
        return qRound(sum/len * 10) / 10;
    }else
    {
        return 0;
    }
}
QList<int> Group_view::Tongji(int type,QList<double>index)
{
    QList<int>Nums;
    int len=index.size();
    int th1,th2;
    switch (type) {
    case 0:
        th1=60;th2=100;
        break;
    case 1:
        th1=90;th2=95;
        break;
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
    case 7:
        th1=30;th2=70;
        break;
    }
    int cnum[3]={0};
    for(int i=0;i<len;i++)
    {
        if(index.at(i)<th1)
            cnum[0]=cnum[0]+1;
        else if(index.at(i)>th2)
            cnum[2]=cnum[2]+1;
        else
            cnum[1]=cnum[1]+1;
    }
    for(int i=0;i<3;i++)
        Nums.push_back(cnum[i]);
    return  Nums;
}
void Group_view::initialWaveChart()
{
    hr_Chart=cc.createLineChart_HR();
    ui->widget_hr->setChart(hr_Chart);
    ui->widget_hr->setRenderHint(QPainter::Antialiasing, true);

    ox_Chart=cc.createLineChart_OX();
    ui->widget_ox->setChart(ox_Chart);
    ui->widget_ox->setRenderHint(QPainter::Antialiasing, true);

    mp_Chart=cc.createLineChart_MP();
    ui->widget_mp->setChart(mp_Chart);
    ui->widget_mp->setRenderHint(QPainter::Antialiasing, true);

    mp_PieChart=cc.createPieChart_MP();
    ui->widget_pie_mp->setChart(mp_PieChart);
    ui->widget_pie_mp->setRenderHint(QPainter::Antialiasing, true);//消除混叠

    hrvHist_BarChart=cc.createHRVHistBarChart();
    ui->widget_HistHRV->setChart(hrvHist_BarChart);
    ui->widget_HistHRV->setRenderHint(QPainter::Antialiasing, true);

    hrvScatterChart=cc.creatScatterchart();
    ui->widget_Scatter->setChart(hrvScatterChart);
    ui->widget_Scatter->setRenderHint(QPainter::Antialiasing, true);

    hrvARAreaChart=cc.createPieChart_PSD();
    ui->widget_AR->setChart(hrvARAreaChart);
    ui->widget_AR->setRenderHint(QPainter::Antialiasing,true);

    //心率，血氧，精神压力，疲劳指数，抑郁，焦虑，自主神经平衡性，自主神经活性
    a_hr_Chart=cc.createPieChart_a_hr();
    ui->widget_pie_a_hr->setChart(a_hr_Chart);
    ui->widget_pie_a_hr->setRenderHint(QPainter::Antialiasing,true);

    a_ox_Chart=cc.createPieChart_a_ox();
    ui->widget_pie_a_ox->setChart(a_ox_Chart);
    ui->widget_pie_a_ox->setRenderHint(QPainter::Antialiasing,true);

    a_mp_Chart=cc.createPieChart_a_mp();
    ui->widget_pie_a_pressure->setChart(a_mp_Chart);
    ui->widget_pie_a_pressure->setRenderHint(QPainter::Antialiasing,true);

    a_fatigure_Chart=cc.createPieChart_a_fatigure();
    ui->widget_pie_a_fatigure->setChart(a_fatigure_Chart);
    ui->widget_pie_a_fatigure->setRenderHint(QPainter::Antialiasing,true);


    a_depress_Chart=cc.createPieChart_a_depress();
    ui->widget_pie_a_depress->setChart(a_depress_Chart);
    ui->widget_pie_a_depress->setRenderHint(QPainter::Antialiasing,true);

    a_ansiety_Chart=cc.createPieChart_a_ansiety();
    ui->widget_pie_a_ansiety->setChart(a_ansiety_Chart);
    ui->widget_pie_a_ansiety->setRenderHint(QPainter::Antialiasing,true);

    a_ballance_Chart=cc.createPieChart_a_ballance();
    ui->widget_pie_a_ballance->setChart(a_ballance_Chart);
    ui->widget_pie_a_ballance->setRenderHint(QPainter::Antialiasing,true);


    a_activity_Chart=cc.createPieChart_a_activity();
    ui->widget_pie_a_activity->setChart(a_activity_Chart);
    ui->widget_pie_a_activity->setRenderHint(QPainter::Antialiasing,true);




}
void Group_view::MyButtionClickeListener1()
{
    widget_btNum=1;
    ui->tabWidget->setCurrentIndex(1);
}
void Group_view::MyButtionClickeListener2()
{
    widget_btNum=2;
    ui->tabWidget->setCurrentIndex(1);
}
void Group_view::MyButtionClickeListener3()
{
    widget_btNum=3;
    ui->tabWidget->setCurrentIndex(1);
}
void Group_view::MyButtionClickeListener4()
{
    widget_btNum=4;
    ui->tabWidget->setCurrentIndex(1);
}
void Group_view::MyButtionClickeListener5()
{
    widget_btNum=5;
    ui->tabWidget->setCurrentIndex(1);
}
void Group_view::MyButtionClickeListener6()
{
    widget_btNum=6;
    ui->tabWidget->setCurrentIndex(1);
}
void Group_view::MyButtionClickeListener7()
{
    widget_btNum=7;
    ui->tabWidget->setCurrentIndex(1);
}
void Group_view::MyButtionClickeListener8()
{
    widget_btNum=8;
    ui->tabWidget->setCurrentIndex(1);
}
void Group_view::MyButtionClickeListener9()
{
    widget_btNum=9;
    ui->tabWidget->setCurrentIndex(1);
}
void Group_view::MyButtionClickeListener10()
{
    widget_btNum=10;
    ui->tabWidget->setCurrentIndex(1);
}
void Group_view::MyButtionClickeListener11()
{
    widget_btNum=11;
    ui->tabWidget->setCurrentIndex(1);
}
void Group_view::MyButtionClickeListener12()
{
    widget_btNum=12;
    ui->tabWidget->setCurrentIndex(1);
}
void Group_view::MyButtionClickeListener13()
{
    widget_btNum=13;
    ui->tabWidget->setCurrentIndex(1);
}
void Group_view::MyButtionClickeListener14()
{
    widget_btNum=14;
    ui->tabWidget->setCurrentIndex(1);
}
void Group_view::MyButtionClickeListener15()
{
    widget_btNum=15;
    ui->tabWidget->setCurrentIndex(1);
}
void Group_view::MyButtionClickeListener16()
{
    widget_btNum=16;
    ui->tabWidget->setCurrentIndex(1);
}
void Group_view::MyButtionClickeListener17()
{
    widget_btNum=17;
    ui->tabWidget->setCurrentIndex(1);
}
void Group_view::MyButtionClickeListener18()
{
    widget_btNum=18;
    ui->tabWidget->setCurrentIndex(1);
}
void Group_view::MyButtionClickeListener19()
{
    widget_btNum=19;
    ui->tabWidget->setCurrentIndex(1);
}
void Group_view::MyButtionClickeListener20()
{
    widget_btNum=20;
    ui->tabWidget->setCurrentIndex(1);
}

void Group_view::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    painter.drawPixmap(rect(),QPixmap(":/images/share/selectmodel_page_bg2.png"),QRect());
}
void Group_view::initServer()
{
    Server::instance();
    connect(this,SIGNAL(command_toClient(int,QJsonObject)),Server::instance(),SLOT(writeMsgToClient(int,QJsonObject)));
    connect(Server::getInstance(),SIGNAL(updateMsg(QJsonObject&)),this,SLOT(receivedMsg(QJsonObject&)));
    connect(Server::getInstance(),SIGNAL(updateClient(QString)),this,SLOT(addNewClient(QString)));
    connect(Server::getInstance(),SIGNAL(removeClient(QString)),this,SLOT(removeClient(QString)));

}
void Group_view::addNewClient(QString address)
{
    qDebug()<<"Connect OK to: "<<address;
}

void Group_view::removeClient(QString address)
{
    qDebug()<<"-------------disConnect to: "<<address<<"-------------";
//    QStringList ip_subList=address.split(":");
//    QString ip=ip_subList[3];
//    DATA_INFO data_Info=hash_data_info[ip];
}
void Group_view::receivedMsg(QJsonObject & json)
{
    if(json.contains("IP"))
    {

        QString cIP=json["IP"].toString();
        DATA_INFO data_Info=hash_data_info[cIP];
        if(data_Info.IP==cIP)
        {
            if(json.contains("socketDescriptor"))
                data_Info.socketDescriptor=json["socketDescriptor"].toInt();

            if(json.contains("fcode"))
            {
                if(json.contains("socketDescriptor"))
                    data_Info.socketDescriptor=json["socketDescriptor"].toInt();
                int fcode=json["fcode"].toInt();
                int icode=json["icode"].toInt();

                if(fcode ==107)
                {
                    //测量结束,将结果显示置空
                    qDebug()<<"107-start";
                    data_Info.mybtn->setUserID("--","--");
                    data_Info.mybtn->setHR("");
                    data_Info.mybtn->setOx("");
                    data_Info.mybtn->setMp("");
                    data_Info.mybtn->setPidian("");
                    qDebug()<<"107-end";
                }

                if(fcode==105)
                {
                    if(icode==0){
                        if(json.contains("userInfoBean"))
                        {
                            qDebug()<<"userInfoBean-start0";
                            UserInfoBean uib= dataPro.Json2UserInfoBean(json["userInfoBean"].toObject());
                            qDebug()<<"userInfoBean-start1";
                            data_Info.mybtn->setUserID(uib.UserID,uib.UserName);
                            qDebug()<<"userInfoBean-end";
                        }
                        if(json.contains("ppgRealTimeIndex"))
                        {
                            qDebug()<<"ppgRealTimeIndex-start";
                            RealTimeIndex rti= dataPro.Json2RealTimeIndex(json["ppgRealTimeIndex"].toObject());
                            data_Info.HR=rti.pr;
                            data_Info.Ox=rti.ox;
                            data_Info.mybtn->setHR(QString::number(rti.pr,'f',1));
                            data_Info.mybtn->setOx(QString::number(rti.ox,'f',1));
                            data_Info.mybtn->setPidian(QString::number(rti.pd,'f',2));
                            data_Info.mybtn->setColor(rti.eleoff);
                            data_Info.iseleoff=rti.eleoff==1;
                            qDebug()<<"eleOOOOOOOOOOOOOOOOOOOOOOOOOOOOf="<<rti.eleoff;
                            if(data_Info.btn_num==widget_btNum)
                            {
                                cc.update_HRData(rti.pr);//更新图
                                cc.update_OXData(rti.ox);
                            }
                            qDebug()<<"ppgRealTimeIndex-end";
                        }
                        if(json.contains("ppgResults"))
                        {
                            qDebug()<<"ppgResults-start";
                            PsychologyIndex psy= dataPro.Json2PsychologyIndex(json["ppgResults"].toObject());
                            if(psy.SPress>0 && psy.SPress<100)
                                data_Info.Spress_List.append(psy.SPress);
                            data_Info.Fatigure=psy.Fatigue;
                            data_Info.Ansiety=psy.Motion;
                            data_Info.Depress=100-psy.Motion;
                            data_Info.Activity=psy.Activity;
                            data_Info.Ballance=psy.Balance;
                            data_Info.AntiPress=psy.AntiPress;
                            data_Info.SDP=psy.sdp;
                            data_Info.PhysicalMentalHealth=psy.PhysicalMentalHealth;
                            if(psy.SPress>0)
                                data_Info.mybtn->setMp(QString::number(psy.SPress,'f',1));
                            for(int i=0;i<28;i++)
                                data_Info.hrvindex[i]=psy.hrvindex[i];

                            for(int i=0;i<psy.rrvalid;i++)
                                data_Info.RR[i]=psy.RR.at(i);
                            data_Info.rrValidLen=psy.rrvalid;
                            if(data_Info.btn_num==widget_btNum && !data_Info.iseleoff )
                            {
                                cc.update_MP_PieData(data_Info.Spress_List);
                                cc.update_MPData(psy.SPress);
                                cc.update_HRVHistBarData(psy.RR,psy.rrvalid);
                                cc.update_HRVScatterData(psy.RR,psy.rrvalid);
                                cc.update_PSD_PieData(psy.vlf,psy.lf,psy.hf);
                            }
                            qDebug()<<"ppgResults-end";
                        }
                    }

                }

            }
            hash_data_info.insert(cIP,data_Info);
        }

    }
    if(json.contains("slotDisconnected"))
    {
        //断开连接去除用户信息显示

    }
}

void Group_view::on_btn_group_all_clicked()
{
    ui->tabWidget->setCurrentIndex(0);
}

void Group_view::on_pushButton_exit_clicked()
{
    bool b=myHelper::ShowMessageBoxQuesion("确认要退出吗？");
    if(b){
        QJsonObject CommandInfo;
        CommandInfo.insert("fcode",809);//功能码（结束测量）
        CommandInfo.insert("icode",1);//信息码，具体训练项目
        CommandInfo.insert("msg","指令下达");
        QHashDataInfoIterator i = hash_data_info.begin();
        for(; i != hash_data_info.end(); ++i)
        {
            DATA_INFO data = i.value();
//            for(int j=0;j<3;j++)
                emit command_toClient(data.socketDescriptor,CommandInfo);
        }
        this->close();
    }
}


void Group_view::on_btn_group_average_clicked()
{
    ui->tabWidget->setCurrentIndex(2);
}

void Group_view::getUserTableInfo(QHashUserTable m_user,QString TaskID,QString Type,QString Scene,int Time)
{
    hash_data_info.clear();
    this->m_userTableHash=m_user;
    this->TaskID=TaskID;
    this->Type=Type;
    this->Scene=Scene;
    this->NeedTime=Time;
    startTime=  QDateTime::currentDateTime();
    QHashUserTableIterator i = m_userTableHash.begin();
    int row = 0;
    DATA_INFO data_Info;
    for(; i != m_userTableHash.end(); ++i)
    {
        USER_TABLE_DATA data = i.value();
        btnBindIP.insert(QString::number(row+1),data.IP);
        data_Info.IP=data.IP;
        data_Info.btn_num=btn_num;
        switch (btn_num) {
        case 1:
            data_Info.mybtn=ui->mybtn1;
            break;
        case 2:
            data_Info.mybtn=ui->mybtn2;
            break;
        case 3:
            data_Info.mybtn=ui->mybtn3;
            break;
        case 4:
            data_Info.mybtn=ui->mybtn4;
            break;
        case 5:
            data_Info.mybtn=ui->mybtn5;
            break;
        case 6:
            data_Info.mybtn=ui->mybtn6;
            break;
        case 7:
            data_Info.mybtn=ui->mybtn7;
            break;
        case 8:
            data_Info.mybtn=ui->mybtn8;
            break;
        case 9:
            data_Info.mybtn=ui->mybtn9;
            break;
        case 10:
            data_Info.mybtn=ui->mybtn10;
            break;
        case 11:
            data_Info.mybtn=ui->mybtn11;
            break;
        case 12:
            data_Info.mybtn=ui->mybtn12;
            break;
        case 13:
            data_Info.mybtn=ui->mybtn13;
            break;
        case 14:
            data_Info.mybtn=ui->mybtn14;
            break;
        case 15:
            data_Info.mybtn=ui->mybtn15;
            break;
        case 16:
            data_Info.mybtn=ui->mybtn16;
            break;
        case 17:
            data_Info.mybtn=ui->mybtn17;
            break;
        case 18:
            data_Info.mybtn=ui->mybtn18;
            break;
        case 19:
            data_Info.mybtn=ui->mybtn19;
            break;
        case 20:
            data_Info.mybtn=ui->mybtn20;
            break;
        default:
            break;
        }
        btn_num++;
        hash_data_info.insert(data.IP,data_Info);
        row++;
    }

}


void Group_view::on_pushButton_end_clicked()
{
    QDateTime endTime=  QDateTime::currentDateTime();
    qint64 intervalTime = startTime.secsTo(endTime);
    //监测时间至少180秒有效才可以保存
    if(intervalTime>NeedTime)
    {
        QString file=Constant::DataBasePath;
        Qt::HANDLE threadId = QThread::currentThreadId();
        QString threadIdStr = QString::number(reinterpret_cast<quintptr>(threadId));

        MySql *mySql = new MySql(file,threadIdStr);
        DataInfoBean dib;
        dib.TaskID=TaskID;

        dib.MeasureTime=endTime .toString("yyyy-MM-dd hh:mm:ss");//格式化时间
        dib.TaskType="团体模式";
        dib.Theme=Type;
        dib.Content=Scene;
        QJsonObject jsonObject;
        QJsonArray jsonArray_UserID,jsonArray_UserName;
        QJsonArray jsonArray_PhysicalMentalHealth,jsonArray_SDP,jsonArray_HR,jsonArray_Ox;


        QJsonObject MyData;
        QHashDataInfoIterator i = hash_data_info.begin();
        int row=0;
        for(; i != hash_data_info.end(); ++i)
        {
            DATA_INFO data = i.value();
            USER_TABLE_DATA utd=m_userTableHash[data.IP];
            jsonArray_UserID.append(utd.nNo);//用户编号
            jsonArray_UserName.append(utd.sName);//用户姓名
            jsonArray_SDP.append(data.SDP);
            jsonArray_HR.append(data.HR);
            jsonArray_Ox.append(data.Ox);
            QJsonArray jsonArray_hrvIndex;
            QJsonArray jsonArray_rr;

            for(int i=0;i<28;i++)
            {
                jsonArray_hrvIndex.append(data.hrvindex[i]);
            }
            for(int i=0;i<data.rrValidLen;i++)
            {
                jsonArray_rr.append(data.RR[i]);
            }

            MyData.insert("rr",jsonArray_rr);
            MyData.insert("hrvIndex",jsonArray_hrvIndex);
            MyData.insert("Score",data.PhysicalMentalHealth);
            MyData.insert("HR",data.HR);
            MyData.insert("Ox",data.Ox);
            MyData.insert("SDP",data.SDP);
            jsonObject.insert(utd.nNo,MyData);//每个人的测量结果数据
            jsonArray_PhysicalMentalHealth.append(data.PhysicalMentalHealth);
            row++;
        }

        jsonObject.insert("Group_Number", row);//团体训练人数
        jsonObject.insert("Train_Type",Type);
        jsonObject.insert("Scene",Scene);
        jsonObject.insert("UseTime",(int)(intervalTime/60));//分钟
        jsonObject.insert("jsonArray_UserID",jsonArray_UserID);
        jsonObject.insert("jsonArray_UserName",jsonArray_UserName);

        jsonObject.insert("jsonArray_SDP",jsonArray_SDP);
        jsonObject.insert("jsonArray_PMH",jsonArray_PhysicalMentalHealth);
        QJsonArray jsonArray_PhysicalMentalHealth_list;

        int pmh_list_size=PhysicalMentalHealth_list_A.size();
        for(int i=0;i<pmh_list_size;i++)
            jsonArray_PhysicalMentalHealth_list.append(PhysicalMentalHealth_list_A.at(i));
        jsonObject.insert("Group_A_PMH_Trend",jsonArray_PhysicalMentalHealth_list);

        dib.TaskResult=QString(QJsonDocument(jsonObject).toJson());
        mySql->MyDataInsert(dib);
        delete mySql;

        //发送平板端退出指令
        QJsonObject CommandInfo;
        CommandInfo.insert("fcode",809);//功能码（结束测量）
        CommandInfo.insert("icode",1);//信息码，具体训练项目
        CommandInfo.insert("msg","指令下达");
        QHashDataInfoIterator ii = hash_data_info.begin();
        for(; ii != hash_data_info.end(); ++ii)
        {
            DATA_INFO data = ii.value();
            emit command_toClient(data.socketDescriptor,CommandInfo);
        }

        this->close();

    }else
    {
        myHelper::ShowMessageBoxInfo("监测时间不到项目所需时间，数据无效！");
    }

}




